/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.nhncorp.neptune.tabletserver;

import java.io.IOException;
import java.util.Map;
import java.util.SortedSet;

import com.nhncorp.neptune.client.Cell;
import com.nhncorp.neptune.client.CellFilter;
import com.nhncorp.neptune.client.Row;
import com.nhncorp.neptune.common.aop.ProxyObject;
import com.nhncorp.neptune.common.conf.NConfiguration;
import com.nhncorp.neptune.fs.ChangeLogFileSystemIF;
import com.nhncorp.neptune.tablet.ColumnValue;
import com.nhncorp.neptune.tablet.TabletInfo;

public interface MemorySSTableIF extends ProxyObject {
  public Searchable getSearcher(Row.Key rowKey, String columnName, Cell.Key cellKey) throws IOException;
  public void clearCompactingColumnCollections();
//  public void deleteChangeLogFile() throws IOException;
  public Map<String, TabletMapFile> saveToDisk(TabletInfo tabletInfo, String fileId) throws IOException;
  public void init(TabletServerIF tabletServer, NConfiguration conf, TabletInfo tabletInfo, int nemOfVersion) throws IOException;
  public void print();
  public boolean loadFromChangeLog() throws IOException;
  public ColumnValue findClosest(Row.Key rowKey, String string) throws IOException;
  public int getTabletSize();
  public void commit(TxId txId, ChangeLog[] changeLogList, boolean saveLog) throws IOException;
  public Scanner getScanner(String columnName, Row.Key startRowKey, Row.Key endRowKey, CellFilter columnFilter) throws IOException;
  public boolean isEmpty();
  public void initMemoryForCompaction() throws IOException;
  public void cancelCompaction(String fileId);
  public ChangeLogFileSystemIF getChangeLogFileSystem();
  public Map<String, ColumnCollection> getColumnCollections();
  public void endChangeLogMinorCompaction() throws IOException;
  public Map<String, ColumnCollection> getCompactingColumnCollections();
  public void setCompacting(boolean compacting);
  public Map<String, TabletMapFile[]> splitAndSave(Row.Key midRowKey, TabletInfo[] splitedTabletInfos) throws IOException;
  public Map<String, TabletMapFile[]> splitAndSaveCanCommit(Row.Key midRowKey, TabletInfo[] splitedTabletInfos) throws IOException;  
  public int[] getDataCount();
  public void obtainWriteLock(String owner);
  public void releaseWriteLock(String owner);
  //public Collection<ColumnValue> search(Row.Key rowKey, String columnName) throws IOException;
  public boolean isDeleted(Row.Key rowKey, String columnName) throws IOException;
  public boolean hasValue(Row.Key rowKey, String columnName) throws IOException;
  /**
   * ROOT, META 테이블 검증용으로 사용된다.
   * 해당 메소드가 호출되는 경우에는 Split 등의 작업이 lock이 걸리기 때문에
   * 메모리의 값에 대한 변경이 거의 없다.
   * @param columnName
   * @return
   */
  public ColumnValue[] getAllMemoryValues(String columnName);
  
  /**
   * MemorySSTable에 있는 rowkey의 목록을 반환한다.
   * @param columnName
   * @return
   */
  public SortedSet<Row.Key> getAllRowKeys();
  public void clearChangeLogOf(String tabletName);
  public void clearAllMemory();
  
  /**
   * Split 처리를 위해 가운데의 rowkey 값을 가져온다. 
   * @throws IOException
   */
  public Row.Key findMidRowKeyForSplit() throws IOException;
}
